Vue.component('myheader',{
    template : `
    <div>
        <div id="header" class="wrap">
        \t<img src="images/logo.gif" />
        </div>
        <div id="navbar" class="wrap">
        \t<div class="profile">
            <label v-if="user.uname">您好, {{user.uname}}
            | <a href="user/logout.s">退出</a>
            </label>
            <label v-else>
                <a href="login.html">请登录</a>
            </label>
        \t\t<span class="return"><a href="index.html">返回列表</a></span>
        \t\t<span class="addnew"><a href="add.html">添加新投票</a></span>
        \t\t
        \t</div>
        \t<div class="search">
        \t\t<form method="post" action="#">
        \t\t\t<input type="text" name="keywords" class="input-text" value=""/><input type="submit" name="submit" class="input-button" value="" />
        \t\t</form>
        \t</div>
    </div>
    
</div>    
    `,
    data(){
        return { user: {} } ;
    },
    created(){
        axios.get("user/getLoginedUser").then(res=>{
            if(res.data){
                this.user = res.data;
            }
        })
    }
});

Vue.component('myfooter',{
   template : `
    <div id="footer" class="wrap">
    \t源辰信息 &copy; 版权所有
    </div>
   `
});

/**
 * 结果处理函数
 * @param res
 * @param vue
 * @param callback
 */
function result(res, vue, callback){
    if(res.data.code==1){
        vue.$message(res.data.msg);
        callback();
    } else {
        vue.$alert(res.data.msg);
    }
}

/**
 * 使用对象属性构建URLSearchParams参数
 * @param obj
 */
function buildParams(obj){
    let params = new URLSearchParams();
    for (let name in obj) {
        params.append(name, obj[name]);
    }
    return params;
}

